﻿using Twitter.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;

namespace Twitter.Drivers
{
    public class TweetButtonPartDriver : ContentPartDriver<TweetButtonPart>
    {
        protected override DriverResult Display(TweetButtonPart part, string displayType, dynamic shapeHelper)
        {
            return ContentShape("Parts_TweetButton",
                                () => shapeHelper.Parts_TweetButton(Username: part.Username,
                                                                RelatedUsername: part.RelatedUsername,
                                                                RelatedUserDescription: part.RelatedUserDescription,
                                                                TweetText: part.TweetText,
                                                                Url: part.Url,
                                                                DataCount: part.DataCount,
                                                                Language: part.Language));
        }

        //GET
        protected override DriverResult Editor(TweetButtonPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_TweetButton_Edit",
                                () => shapeHelper.EditorTemplate(TemplateName: "Parts/Twitter/TweetButton", Model: part));
        }

        //POST
        protected override DriverResult Editor(TweetButtonPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}